package com.itrencai.d20_proxy;

public class UserServiceImpl implements UserService{
    @Override
    public String login(String loginName, String passWord) {
        //有代理完成喽
        //long startTimer = System.currentTimeMillis();
        try {

            Thread.sleep(1000);

            if ("admin".equals(loginName) && "123456".equals(passWord)) {
                return "success";
            }
            return "用户名或密码错误";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        } finally {
            //有代理完成喽

//            long endTimer = System.currentTimeMillis();
//            System.out.println("login方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");
        }

    }

    @Override
    public void selectUsers() {
        //long startTimer = System.currentTimeMillis();
        System.out.println("查询了100个用户的数据！");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        long endTimer = System.currentTimeMillis();
//        System.out.println("select方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");



    }

    @Override
    public boolean deleteUsers() {
//        long startTimer = System.currentTimeMillis();

        try {
            System.out.println("删除了100个用户的数据！");
            Thread.sleep(500);
            return  true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;

        }finally {
//            long endTimer = System.currentTimeMillis();
//            System.out.println("delete方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");
        }


    }

    @Override
    public void updateUsers() {
        try {
            System.out.println("修改了100个用户的数据！");
            Thread.sleep(2500);

        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}
